﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace SZ.Mech
{
    public class CompProperties_EMPIgnore : CompProperties
    {
        public CompProperties_EMPIgnore()
        {
            this.compClass = typeof(EMPIgnoreComp);
        }
    }
    public class EMPIgnoreComp : ThingComp//天兵生成已经完成了
    {

        public override void PostPostApplyDamage(DamageInfo dinfo, float totalDamageDealt)
        { 
            if((parent as Pawn).Dead) return;

            base.PostPostApplyDamage(dinfo, totalDamageDealt);

            Pawn_StanceTracker stance = (parent as Pawn).stances;
            if (stance.stunner is StunHandler)
            {
                FieldInfo value = typeof(StunHandler).GetField("stunFromEMP", BindingFlags.NonPublic | BindingFlags.Instance);
                bool stunFromEMP =  (bool)value.GetValue(stance.stunner);
                if(stunFromEMP)
                {
                    FieldInfo value2 = typeof(StunHandler).GetField("stunTicksLeft", BindingFlags.NonPublic | BindingFlags.Instance);
                    value2.SetValue(stance.stunner, 0);
                    FieldInfo value3 = typeof(StunHandler).GetField("EMPAdaptedTicksLeft", BindingFlags.NonPublic | BindingFlags.Instance);
                    value3.SetValue(stance.stunner, 0);
                }
            }
        }
    }
}
